package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.CustomerUser;
import com.k.demo.entity.RedBag;
import com.k.demo.mapper.CustomerUserMapper;
import com.k.demo.service.CustomerUserService;

@Service
public class CustomerUserServiceImpl implements CustomerUserService {
	
	@Autowired
	private CustomerUserMapper customeruserMapper;
	
	@Override
	public CustomerUser login(String user_msg,String user_pwd){
				
		return customeruserMapper.selectByIdAndPwd(user_msg,user_pwd);
	}
	@Override
	public int insertCustomerUser(CustomerUser customeruser) {
		int count = customeruserMapper.insertCustomerUser(customeruser);
		System.out.println(customeruser.getUser_id());
		if (count<0) {//插入直接返回插入用户的id
			return -1;//影响记录数为-1时即表示插入失败
		}
		
		return customeruser.getUser_id();
	}
	
	@Override
	public CustomerUser getCustomerUserByUserid(int userid) {
		
		return customeruserMapper.selectCustomerUserByUserid(userid);
	}

	@Override
	public boolean updateCustomerUser(CustomerUser customerUser) {
		
		return customeruserMapper.updateUserinfo(customerUser)>0;
	}

	@Override
	public boolean deleteCustomerUser(int userid) {
		// TODO Auto-generated method stub
		return customeruserMapper.deleteCustomerUser(userid)>0;
	}
	@Override
	public List<CustomerUser> getAll() {
		// TODO Auto-generated method stub
		return customeruserMapper.selectAllCustomerUsers();
	}
	@Override
	public CustomerUser getCustomerUserByUserName(String username) {
		// TODO Auto-generated method stub
		return customeruserMapper.selectCustomerUserByUserName(username);
	}
	@Override
	public int deleteForEach(List<Integer> userlist) {
		// TODO Auto-generated method stub
		return customeruserMapper.deleteCustomerUserForEach(userlist);
	}
	@Override
	public List<CustomerUser> getCustomerUserByIdOrName(String user_msg) {
		// TODO Auto-generated method stub
		return customeruserMapper.selectCustomerUserByIdOrName(user_msg);
	}
	@Override
	public List<CustomerUser> getCustomerUserByKind(int user_kind) {
		// TODO Auto-generated method stub
		return customeruserMapper.selectCustomerUserByKind(user_kind);
	}
	@Override
	public List<CustomerUser> getCustomerUserByUserNameAndUserKind(CustomerUser customeruser) {
		// TODO Auto-generated method stub
		return customeruserMapper.selectCustomerUserByKindAndName(customeruser);
	}
	
	//分页查找全部
	public PageInfo<CustomerUser> getAlltWithPage(int pageNum, int pageSize) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<CustomerUser>(customeruserMapper.getAll());
	}
	@Override
	public List<Integer> getIdByName(String user_true_name) {
		// TODO Auto-generated method stub
		return customeruserMapper.getIdByName(user_true_name);
	}
	@Override
	public List<CustomerUser> getByIdList(List<Integer> user_id) {
		// TODO Auto-generated method stub
		return customeruserMapper.selectByIdList(user_id);
	}
	
	//根据传入的对象进行动态组合查询
	public PageInfo<CustomerUser> getSearchResutlttWithPage(int pageNum, int pageSize, CustomerUser customeruser) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<CustomerUser>(customeruserMapper.selectByUserInfo(customeruser));
	}


}
